home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / gnu / gnulib / ohlutil / system.h < prev    next >
Encoding:
C/C++ Source or Header  |  1990-08-24  |  5.1 KB  |  229 lines

  1. /* system-dependent definitions for fileutils programs.
  2.    Copyright (C) 1989, 1990 Free Software Foundation, Inc.
  3.  
  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 1, or (at your option)
  7.    any later version.
  8.  
  9.    This program is distributed in the hope that it will be useful,
  10.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.    GNU General Public License for more details.
  13.  
  14.    You should have received a copy of the GNU General Public License
  15.    along with this program; if not, write to the Free Software
  16.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  17.  
  18. /*
  19.  * MS-DOS port (c) 1990 by Thorsten Ohl, td12@ddagsi3.bitnet
  20.  *
  21.  * To this port, the same copying conditions apply as to the
  22.  * original release.
  23.  *
  24.  * IMPORTANT:
  25.  * This file is not identical to the original GNU release!
  26.  * You should have received this code as patch to the official
  27.  * GNU release.
  28.  *
  29.  * MORE IMPORTANT:
  30.  * This port comes with ABSOLUTELY NO WARRANTY.
  31.  *
  32.  * $Header: e:/gnu/fileutil/RCS/system.h'v 1.3.0.5 90/06/29 00:37:37 tho Stable $
  33.  */
  34.  
  35. /* Include sys/types.h before this file.  */
  36.  
  37. #include <sys/stat.h>
  38.  
  39. #ifdef USG
  40. #ifdef MSDOS
  41. #include <time.h>
  42. #else /* not MSDOS */
  43. #include <sys/times.h>
  44. #endif /* not MSDOS */
  45. #else
  46. #include <sys/time.h>
  47. #endif
  48.  
  49. #ifdef _POSIX_SOURCE
  50. #include <unistd.h>
  51. #include <limits.h>
  52. #else
  53. #ifndef MSDOS
  54. #include <sys/param.h>
  55. #endif /* not MSDOS */
  56. #define _POSIX_PATH_MAX 255
  57. #define _POSIX_NAME_MAX 14
  58. #ifndef PATH_MAX
  59. #ifdef MAXPATHLEN
  60. #define PATH_MAX MAXPATHLEN
  61. #else
  62. #define PATH_MAX _POSIX_PATH_MAX
  63. #endif
  64. #endif
  65. #ifndef NAME_MAX
  66. #ifdef MAXNAMLEN
  67. #define NAME_MAX MAXNAMLEN
  68. #else
  69. #define NAME_MAX _POSIX_NAME_MAX
  70. #endif
  71. #endif
  72. #endif
  73.  
  74. /* Filesystem device blocksize. */
  75. #ifndef DEV_BSIZE
  76. #ifdef BSIZE
  77. #define DEV_BSIZE BSIZE
  78. #else
  79. #define DEV_BSIZE 512
  80. #endif
  81. #endif
  82.  
  83. #ifdef _POSIX_SOURCE
  84. #define major(dev)  (((dev) >> 8) & 0xff)
  85. #define minor(dev)  ((dev) & 0xff)
  86. #define makedev(maj, min)  (((maj) << 8) | (min))
  87. #else
  88. #ifdef USG
  89. #ifdef MSDOS
  90. #define major(dev)  (((dev) >> 8) & 0xff)
  91. #define minor(dev)  ((dev) & 0xff)
  92. #else /* not MSDOS */
  93. #include <sys/sysmacros.h>
  94. #endif /* not MSDOS */
  95. #endif
  96. #endif
  97.  
  98. #ifdef _POSIX_SOURCE
  99. #include <utime.h>
  100. #else
  101. struct utimbuf
  102. {
  103.   long actime;
  104.   long modtime;
  105. };
  106. #ifdef MSDOS
  107. int utime(char *, struct utimbuf *);
  108. #endif /* MSDOS */
  109. #endif
  110.  
  111. #if defined(USG) || defined(_POSIX_SOURCE)
  112. #include <string.h>
  113. #define index strchr
  114. #define rindex strrchr
  115. #define bcopy(from, to, len) memcpy ((to), (from), (len))
  116.  
  117. #ifndef _POSIX_SOURCE
  118. /* Args for access. */
  119. #define F_OK 0
  120. #define X_OK 1
  121. #define W_OK 2
  122. #define R_OK 4
  123.  
  124. char *getcwd ();
  125. #endif
  126. #define getwd(buf) getcwd ((buf), PATH_MAX + 2)
  127.  
  128. /* Args for lseek. */
  129. #define L_SET 0
  130. #define L_INCR 1
  131. #define L_XTND 2
  132. #else
  133. #include <strings.h>
  134. #include <sys/file.h>
  135.  
  136. char *getwd ();
  137. #endif
  138.  
  139. #include <fcntl.h>
  140.  
  141. #ifdef MSDOS
  142.  
  143. #include "msd_dir.h"
  144. #define NLENGTH(direct) ((direct)->d_namlen)
  145.  
  146. #else /* not MSDOS */
  147.  
  148. #ifdef DIRENT
  149. #include <dirent.h>
  150. #define direct dirent
  151. #define NLENGTH(direct) (strlen((direct)->d_name))
  152. #else
  153. #define NLENGTH(direct) ((direct)->d_namlen)
  154. #ifdef USG
  155. #ifdef SYSNDIR
  156. #include <sys/ndir.h>
  157. #else
  158. #include <ndir.h>
  159. #endif
  160. #else /* must be BSD */
  161. #include <sys/dir.h>
  162. #endif
  163. #endif
  164.  
  165. #endif /* !MSDOS */
  166.  
  167.  
  168. #ifdef MSDOS
  169.  
  170. #define ST_BLKSIZE(statbuf) BLKSIZE
  171. #define ST_NBLOCKS(statbuf) (((statbuf).st_size + DEV_BSIZE - 1) / DEV_BSIZE)
  172.  
  173. #else /* not MSDOS */
  174.  
  175. /* Extract data from a `struct stat'.
  176.    ST_BLKSIZE: Optimal I/O blocksize for the file.
  177.    ST_NBLOCKS: Number of blocks in the file (including indirect blocks). */
  178. #ifdef _POSIX_SOURCE
  179. #define ST_BLKSIZE(statbuf) DEV_BSIZE
  180. #define ST_NBLOCKS(statbuf) (((statbuf).st_size + DEV_BSIZE - 1) / DEV_BSIZE)
  181. #else
  182. #ifdef STBLOCKS_MISSING
  183. #define ST_BLKSIZE(statbuf) DEV_BSIZE
  184. #define ST_NBLOCKS(statbuf) (st_blocks ((statbuf).st_size))
  185. #else
  186. /* Some systems, like Sequents, return st_blksize of 0 on pipes. */
  187. #define ST_BLKSIZE(statbuf) ((statbuf).st_blksize > 0 \
  188.                  ? (statbuf).st_blksize : DEV_BSIZE)
  189. #define ST_NBLOCKS(statbuf) ((statbuf).st_blocks)
  190. #endif
  191. #endif
  192.  
  193. #endif /* not MSDOS */
  194.  
  195. /* Convert B blocks of DEV_BSIZE bytes
  196.    to kilobytes if K is nonzero, otherwise to blocks of 512 bytes. */
  197.  
  198. #if DEV_BSIZE == 512
  199. #define convert_blocks(b, k) ((k) ? ((b) + 1) / 2 : (b))
  200. #else
  201. #if DEV_BSIZE == 1024
  202. #define convert_blocks(b, k) ((k) ? (b) : (b) * 2)
  203. #else
  204. #define convert_blocks(b, k) ((k) \
  205.                   ? ((b) * DEV_BSIZE + 1023) / 1024 \
  206.                   : ((b) * DEV_BSIZE + 511) / 512)
  207. #endif
  208. #endif
  209.  
  210. #ifndef S_IFLNK
  211. #define lstat stat
  212. #endif
  213.  
  214. #ifndef SIGTYPE
  215. #define SIGTYPE void
  216. #endif
  217.  
  218. #ifdef __GNUC__
  219. #define alloca __builtin_alloca
  220. #else
  221. #ifdef sparc
  222. #include <alloca.h>
  223. #else
  224. #ifndef MSDOS                /* use <malloc.h> */
  225. char *alloca ();
  226. #endif /* not MSDOS */
  227. #endif
  228. #endif
  229.